/*
 * All rights Reserved, Designed By Rylynn
 * @ClassName:  Edge
 * @Description:
 * @author: rylynn
 * @date:   2021/7/7
 *
 */

package org.etnetwork.core;

import com.google.common.base.Preconditions;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Edge implements Serializable {
    final Long serialVersionUID = 1L;
    private Long source;
    private Long target;
    private Map<String, Object> properties;


    public Edge(Long source, Long target, Map<String, Object> properties) {
        Preconditions.checkArgument(source >= 0, String.format("The source node id of an edge should be not less than 0, but get %d.", source));
        Preconditions.checkArgument(target >= 0, String.format("The target node id of an edge should be not less than 0, but get %d.", target));
        this.source = source;
        this.target = target;
        this.properties = properties;
    }

    public Edge(Vertex source, Vertex target, Map<String, Object> properties) {
        this(source.getVid(), target.getVid(), properties);
    }

    public Edge(Vertex source, Vertex target) {
        this(source, target, new HashMap<>());
    }

    public Edge(Long source, Long target) {
        this(source, target, new HashMap<>());
    }

    public Long getSource() {
        return source;
    }

    public void setSource(Long source) {
        this.source = source;
    }

    public Long getTarget() {
        return target;
    }

    public void setTarget(Long target) {
        this.target = target;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }

    public void addProperty(String key, Object value) {
        this.properties.put(key, value);
    }

    public void updateProperty(String key, Object value) {
        this.properties.put(key, value);
    }

}
